import routes from 'server/route/index';
import utils from 'server/core/utils';
import PlayerModel from 'server/model/playerModel';
import playerHandle from 'server/handle/playerHandle';
import playerStorage from 'js/core/playerStorage';

//角色登陆
routes.setUserLogin('selectPlayer', null, (msg, cb) => {
	let data = playerStorage.get();
	let player = null;
	if (!data) {
		player = playerHandle.createPlayer('单日哥');
	} else {
		player = new PlayerModel(data);
	}
	// playerHandle.initPlayer(player);
	playerStorage.set(player);
	cb(0, player);
}, {
	1: '角色不存在'
});

//创建角色
routes.setUserLogin('createPlayer', [
	['name', 'string']
], (session, msg, cb) => {
	let name = msg.name;
	let player = new PlayerModel();
	player.name = name;
	playerStorage.set(player);
	// playerStorage.save();
	cb(0);
}, {
	1: '角色名已存在',
});